package com.platform.controller.platform;

import com.platform.common.annotation.Log;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.core.page.TableDataInfo;
import com.platform.common.enums.BusinessType;
import com.platform.common.enums.ResultEnum;
import com.platform.common.exception.BusinessException;
import com.platform.system.domain.dto.device.FirmwareInfoDto;
import com.platform.system.domain.dto.device.UpgradeTaskDto;
import com.platform.system.domain.vo.device.FirmwareInfoVo;
import com.platform.system.domain.vo.device.UpgradeTaskVo;
import com.platform.system.service.ISysUpgradeTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Huangkai
 */
@Slf4j
@RestController
@RequestMapping("/device/upgradeTask")
public class UpgradeTaskController {

    @Resource
    ISysUpgradeTaskService sysUpgradeTaskService;

    /**
     * 查询升级任务
     */
    @Log(title = "查询固件", businessType = BusinessType.OTHER)
    @GetMapping("/selectUpgradeTaskList")
    public TableDataInfo selectUpgradeTaskList(@Validated UpgradeTaskVo upgradeTaskVo) {
        return sysUpgradeTaskService.selectUpgradeTaskList(upgradeTaskVo);
    }

    /**
     * 查询详情
     */
    @Log(title = "查询详情", businessType = BusinessType.OTHER)
    @GetMapping("/selectUpgradeTask/{uid}")
    public AjaxResult selectUpgradeTask(@PathVariable(value = "uid") String uid) {
        UpgradeTaskDto upgradeTaskDto = sysUpgradeTaskService.selectUpgradeTask(uid);
        if(upgradeTaskDto == null){
            throw new BusinessException(ResultEnum.DATA_NOT_EXIST);
        }
        return AjaxResult.success(upgradeTaskDto);
    }

    /**
     * 修改
     */
    @Log(title = "新增删除任务", businessType = BusinessType.UPDATE)
    @PostMapping("/insertUpgradeTask")
    public AjaxResult insertUpgradeTask(@RequestBody @Validated UpgradeTaskVo upgradeTaskVo) {
        return sysUpgradeTaskService.insertUpgradeTask(upgradeTaskVo);
    }

    /**
     * 更新任务
     */
    @Log(title = "更新任务", businessType = BusinessType.UPDATE)
    @PostMapping("/updateUpgradeTaskStatus")
    public AjaxResult updateUpgradeTaskStatus(@RequestBody @Validated UpgradeTaskVo upgradeTaskVo) {
        return sysUpgradeTaskService.updateUpgradeTaskStatus(upgradeTaskVo);
    }

    /**
     * 修改
     */
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/updateUpgradeTask")
    public AjaxResult updateUpgradeTask(@RequestBody @Validated UpgradeTaskVo upgradeTaskVo) {
        return sysUpgradeTaskService.updateUpgradeTask(upgradeTaskVo);
    }

    /**
     * 删除
     */
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @PostMapping("/deleteUpgradeTask")
    public AjaxResult deleteUpgradeTask(@RequestBody @Validated UpgradeTaskVo upgradeTaskVo) {
        return sysUpgradeTaskService.deleteUpgradeTask(upgradeTaskVo);
    }
}
